//
//  Set+AG.swift
//  BWExtensionKit
//
//  Created by zhuxuhong on 2022/2/21.
//

import Foundation
import BWToolKit


public typealias DateComponentValueSet = Set<[Calendar.Component: String]>

extension DateComponentValueSet {
    public static let quotation: DateComponentValueSet = [
        [.day: "'"],
        [.hour: "’"],
        [.minute: "‘’"],
        [.second: "‘’‘"]
    ]
    public static let cnShort: DateComponentValueSet = [
        [.day: "天"],
        [.hour: "时"],
        [.minute: "分"],
        [.second: "秒"]
    ]
    public static let cnLong: DateComponentValueSet = [
        [.day: "天"],
        [.hour: "小时"],
        [.minute: "分钟"],
        [.second: "秒"]
    ]
    public static let enShort: DateComponentValueSet = [
        [.day: "D"],
        [.hour: "H"],
        [.minute: "M"],
        [.second: "S"]
    ]
    public static let enLong: DateComponentValueSet = [
        [.day: "Days"],
        [.hour: "Hours"],
        [.minute: "Minutes"],
        [.second: "Seconds"]
    ]
}

extension Set where Element: Hashable {
    public mutating func bw_remove(where handler: @escaping BlockTR<Element,Bool>) -> Self {
        for item in self {
            if handler(item) == true {
                remove(item)
            }
        }
        return self
    }
}

extension Set where Element == Calendar.Component {
    public static let full: DateComponentSet = [
        .year, .month, .day, .hour, .minute, .second, .nanosecond
    ]
    public static let fullToSeconds: DateComponentSet = {
        var sets = full
        sets.remove(.nanosecond)
        return sets
    }()
    public static let fullToMinutes: DateComponentSet = {
        var sets = fullToSeconds
        sets.remove(.second)
        return sets
    }()
    public static let fullToHours: DateComponentSet = {
        var sets = fullToMinutes
        sets.remove(.minute)
        return sets
    }()
    public static let yearMonthDays: DateComponentSet = {
        var sets = fullToHours
        sets.remove(.hour)
        return sets
    }()
}
